package org.BUPT.admin.system.controller;

import org.BUPT.modules.system.domain.Subject;
import org.BUPT.modules.system.domain.User;
import org.BUPT.modules.system.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/dataservice")
public class InterfaceControllor {
    /**
     * 传入用户id
     * @return 返回用户角色ID
     */

    @Autowired
    SubjectService subjectService;

    @GetMapping("/getuserrole")
    public String getUserRole(@RequestParam("userId") User user){
        return String.valueOf(user.getRole().getId());
    }

    @GetMapping("/getsubjectteachers")
    public List<User> getSubjectTeachers(@RequestParam("subjectId") String subjectId){
        return subjectService.getSutents(Long.valueOf(subjectId));
    }

    @GetMapping("/getsubjectstudents")
    public List<User> getSubjectStudents(@RequestParam("subjectId") String subjectId){
        return subjectService.getSutents(Long.valueOf(subjectId));
    }

    @GetMapping("/getuserinfo")
    public User getUserInfo(@RequestParam("userId") User user){
        return user;
    }

    @GetMapping("/getusersubject")
    public List<Subject> getUserSubject(@RequestParam("userId") User user){
        return subjectService.getSubjectsByUserId(user.getId());
    }
}
